# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import re

class TrispiderPipeline(object):
    def process_item(self, item, spider):
        # for i in range(0, len(item["name"])):
        name = item["name"].replace('/','\\')
        teacher = item["teacher"].replace("讲师：","")
        price = item["price"]
        price = re.findall("(\d+[.]\d+)", price, re.S)[0]
        course_num = item["course_num"]
        student_num = item["student_num"]
        # detailurl = item["detailurl"]

        f = open(r'course/%s.txt' % name, "w")
        f.write("课程名：%s \n" % name)
        f.write("学员人数：%s \n" %student_num)
        f.write("课程定价：%s \n" % price)
        f.write("课时数：%s \n" % course_num)
        f.close()
